Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mkfs: avoid blockdev failing to re-read partition table #275

Merged
merged 1 commit into from
Aug 14, 2024
Merged

Conversation

mika
Copy link
Member

@mika mika commented Apr 25, 2024

Invoking blockdev --rereadpt straight after creating the file system might fail with:

blockdev: ioctl error on BLKRRPART: Device or resource busy
Unexpected non-zero exit code 1 in /sbin/grml-debootstrap /sbin/grml-debootstrap /sbin/grml-debootstrap at line 1376 2132 0 detected!
last bash command: blockdev --rereadpt "$main_device"

This is caused by udev kicking in and causing a race condition. Let's invoke udevadm settle (which watches the udev event queue, and exits if all current events are handled), and then retry blockdev --rereadpt ... up to 30 times/seconds.

Thanks: Darshaka Pathirana for bug report and initial investigation, and Chris Hofstaedtler for feedback
Closes: #273

Invoking `blockdev --rereadpt` straight after creating the file system
might fail with:

| blockdev: ioctl error on BLKRRPART: Device or resource busy
| Unexpected non-zero exit code 1 in /sbin/grml-debootstrap /sbin/grml-debootstrap /sbin/grml-debootstrap at line 1376 2132 0 detected!
| last bash command: blockdev --rereadpt "$main_device"

This is caused by udev kicking in and causing a race condition. Let's
invoke udevadm settle (which watches the udev event queue, and exits if
all current events are handled), and then retry `blockdev --rereadpt
...` up to 30 times/seconds.

Thanks: Darshaka Pathirana for bug report and initial investigation, and Chris Hofstaedtler for feedback
Closes: #273
@mika mika requested review from zeha and jkirk April 25, 2024 15:15
@jkirk
Copy link
Contributor

jkirk commented Jun 7, 2024

Disclaimer: I am not a fan of sleep loops, but I guess any other solution would need something similar "under the hood".

Just tested the PR and it works for me:

root@grml ~ # ./grml-debootstrap -r bookworm -t /dev/sda1 --grub /dev/sda --hostname grml-debootstrap --mirror http://mirror.hetzner.de/debian/packages

 * EFI support detected, but system seems to be running in BIOS mode.
 * grml-debootstrap [0.108] - Please recheck configuration before execution:

   Target:          /dev/sda1
   Install grub:    /dev/sda
   Install efi:     no
   Using release:   bookworm
   Using hostname:  grml-debootstrap
   Using mirror:    http://mirror.hetzner.de/debian/packages
   Using arch:      amd64
   Config files:    /etc/debootstrap

   Important! Continuing will delete all data from /dev/sda1!

 * Is this ok for you? [y/N] y
[...]
mke2fs 1.47.0 (5-Feb-2023)
/dev/sda1 contains a ext4 file system
        created on Fri Jun  7 09:56:39 2024
Proceed anyway? (y,N) y
Discarding device blocks: done                            
Creating filesystem with 2096896 4k blocks and 524288 inodes
Filesystem UUID: 43bba0a1-121f-4666-95ee-2220b6d31079
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done 

 * Disabling automatic filesystem check on /dev/sda1 via tune2fs
tune2fs 1.47.0 (5-Feb-2023)
Setting maximal mount count to -1
Setting interval between checks to 0 seconds
 * Mounting /dev/sda1 to /mnt/debootstrap.9433
mount: (hint) your fstab has been modified, but systemd still uses
       the old version; use 'systemctl daemon-reload' to reload.
 * Identified UUID 43bba0a1-121f-4666-95ee-2220b6d31079 for /dev/sda1
 * Running debootstrap  for release bookworm (amd64) using http://mirror.hetzner.de/debian/packages
 * Executing: debootstrap --arch amd64  bookworm /mnt/debootstrap.9433 http://mirror.hetzner.de/debian/packages
[...]

I can not recall the mount: (hint) your fstab has been modified line, but apart from that, the fix works.

if [ "${success}" = "0" ] ; then
eerror "Error: failed to reread partition table, giving up."
bailout 1
fi
fi
fi
# give the system 2 seconds, otherwise we might run into
Copy link
Contributor

@jkirk jkirk Jun 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, JFTR: I also tested removing the sleep 2 line below your change and it worked for me.

@mika mika merged commit bbd512f into master Aug 14, 2024
72 of 78 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

blockdev: ioctl error on BLKRRPART: Device or resource busy
2 participants